﻿// http://blogs.msdn.com/b/crminthefield/archive/2011/06/03/microsoft-dynamics-crm-2011-custom-contact-entry-website-using-early-bound-entity-classes.aspx

namespace CRM2011.Service
{
	public static class Connection
	{
		public static Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy GetService()
		{
			Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy service = null;
			int timeoutMinutes = 10;
			System.ServiceModel.Description.ClientCredentials creds = new System.ServiceModel.Description.ClientCredentials();

			System.String strUri = string.Format("{0}{1}/{2}", "http://10.0.7.2:5555/", "CRMDEV", "xrmservices/2011/organization.svc");

			System.Uri serviceUrl = new System.Uri(strUri);

			creds.Windows.ClientCredential = new System.Net.NetworkCredential("alexandras", "Espressoft01");

			service = new Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy(serviceUrl, null, creds, null);

			service.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new Microsoft.Xrm.Sdk.Client.ProxyTypesBehavior());
			service.Timeout = new System.TimeSpan(0, timeoutMinutes, 0);

			return service;
		}
	}

}